using System;
using UnityEngine;

[Serializable]
[AddComponentMenu("Camera-Control/Smooth FollowARC")]
public class SmoothFollowArcade : MonoBehaviour
{
	private int state;

	public Transform targetpos;

	public Transform playerpos;

	public float rdistance;

	public Transform target;

	public float height;

	public float heightDamping;

	private Transform tr;

	public float wantedHeight;

	private float tilt;

	public bool mp;

	public SmoothFollowArcade()
	{
		state = 1;
		height = 5f;
		heightDamping = 2f;
		wantedHeight = 3.2f;
	}

	public void Start()
	{
		StateManager.heightLimit = 3;
		tr = transform;
		if (!mp)
		{
			playerpos = GameObject.Find("knight dranzer").transform;
		}
		tilt = 1.8f;
		tr.rotation = Quaternion.Euler(70f, 0f, 0f);
		if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name.Contains("MP"))
		{
			Invoke("mpfind", 0.2f);
		}
	}

	public void LateUpdate()
	{
		Vector3 position = tr.position;
		float y = position.y;
		Transform transform = tr;
		Vector3 position2 = tr.position;
		Vector3 position3 = target.position;
		float x = position3.x;
		float y2 = Mathf.Lerp(y, wantedHeight, 50f * Time.deltaTime);
		Vector3 position4 = target.position;
		transform.position = Vector3.Lerp(position2, new Vector3(x, y2, position4.z - tilt), 4f * Time.deltaTime);
	}

	public void checkstate()
	{
		if ((bool)targetpos)
		{
			height = rdistance + 2f;
			rdistance = Vector3.Magnitude(playerpos.position - targetpos.position);
			Vector3 position = target.position;
			wantedHeight = Mathf.Clamp(position.y + height, StateManager.heightLimit, 20f);
		}
	}

	public void checkstart()
	{
		wantedHeight = 3.2f;
	}

	public void mpfind()
	{
		target = GameObject.Find("PlayerPrefab(Clone)").transform;
		playerpos = GameObject.Find("PlayerPrefab(Clone)").transform;
	}

	public void Main()
	{
		InvokeRepeating("checkstate", 5.5f, 0.14f);
		Invoke("checkstart", 0f);
	}
}
